package com.zztl.infiniteBand.ui.activity

import android.app.Activity
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.adapter.AddressAdapter
import com.zztl.infiniteBand.base.BaseMvpActivity
import com.zztl.infiniteBand.model.AddressListBean
import com.zztl.infiniteBand.presenter.AddressPresenter
import com.zztl.infiniteBand.ui.view.mvpview.AddressListView
import com.zztl.infiniteBand.ui.view.recycleview.SimpleItemDecoration
import kotlinx.android.synthetic.main.activity_record.*
import java.util.*

class AddressRecordActivity : BaseMvpActivity<AddressListView, AddressPresenter>(), BaseQuickAdapter.OnItemClickListener, AddressListView {

   /* @BindView(R.id.rv)
    lateinit var rv: RecyclerView
*/
    private var mAdapter: AddressAdapter? = null
    var datas: List<String> = ArrayList()
    lateinit var mAddressPresenter: AddressPresenter

    override fun setLayoutId(): Int = R.layout.activity_address_record


    override fun initBase() {
        setTitle(getString(R.string.历史地址))
        mAdapter = AddressAdapter(R.layout.item_address, datas)
        rv.layoutManager = LinearLayoutManager(this)
        rv.adapter = mAdapter
        rv.addItemDecoration(SimpleItemDecoration(this))
        mAdapter!!.onItemClickListener = this
        mAddressPresenter.getAddressList(this)
    }

    override fun createPresenter(): AddressPresenter {
        mAddressPresenter = AddressPresenter()
        return mAddressPresenter
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        val intent = Intent(this, MentionActivity::class.java)
        intent.putExtra("address", mAdapter!!.data[position])
        setResult(Activity.RESULT_OK, intent)
        finish()
    }

    override fun getSuccess(bean: AddressListBean) {
        mAdapter!!.setNewData(bean.data!!.rows)
    }
}
